#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>

#include <stdio.h>
#include <pthread.h>

int main(void)
{
	const char *ptr = "www.sina.com.cn";
	char **pptr;
	struct hostent *hptr;
	char str[32];

	printf("I am CPP in android for Surface!\n");

	if( (hptr = gethostbyname(ptr) ) == NULL ) {
		printf("gethostbyname error for host:%s\n", ptr);
	}

	switch(hptr->h_addrtype) {
		case AF_INET:
		case AF_INET6:
			pptr=hptr->h_addr_list;
			for(;*pptr!=NULL;pptr++) {
				printf(" host[%s]\t", ptr);
				printf(" address:%s\n", inet_ntop(hptr->h_addrtype, *pptr, str, sizeof(str)));
			}
			break;

		default:
			printf("unknown address type\n");
			break;
	}

	return 0;
}
